﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GCD;
using gds_classes;

namespace e_customer
{
    public class Customer
    {
        private int r { get; set; }
        private int n { get; set; }
        public int N { get; set; }
        public int d { get; set; }
        private int inv_r;

        public Customer(int N, int d)
        {
            this.N = N;
            this.d = d;
            Random rnd=new Random();
            this.r = 67;// rnd.Next(2, this.N/2);

            while (gcd.GCDSimple(this.r, this.N) != 1 && this.r < this.N)   // Weak
            {
                this.r++;
            }
            if (this.r >= this.N)
            {
                throw new Exception();
            }

            this.inv_r = MathMethods.FindInversion(this.r, this.N);
        }

        public int GetAnonymousN(int n)
        {
            if (n % 10 != n / 10)
            {
                return -1;
            }
            this.n = n;

            return ((n % this.N) * (MathMethods.PowByMod(this.r, this.d, this.N))) % this.N;
        }

        public int[] EvaluteCash(int s_k)
        {
            return new int[] { this.n, (s_k * inv_r) % this.N };
        }
    }
}
